<template>
	<view>
		<navbar name="甘油三酯"></navbar>
		<view class="weui-flex">
			<view>
				<view class="placeholder titleView">
					甘油三酯
				</view>
			</view>
			<view class="weui-flex__item">
				<view class="placeholder toolView" :class="label3 == '请选择甘油三酯'?'':'colorA4'"
					@click="handleTap('picker3')">
					{{label3}}
				</view>
			</view>
		</view>
		<u-line />
		<view class="weui-flex">
			<view>
				<view class="placeholder titleView">
					高密度脂蛋白（HDL）
				</view>
			</view>
			<view class="weui-flex__item">
				<view class="placeholder toolView" :class="label2 == '请选择高密度脂蛋白'?'':'colorA4'"
					@click="handleTap('picker2')">
					{{label2}}
				</view>
			</view>
		</view>
		<u-line />

		<view class="weui-flex">
			<view>
				<view class="placeholder titleView">
					低密度脂蛋白（LDL）
				</view>
			</view>
			<view class="weui-flex__item">
				<view class="placeholder toolView" :class="label4 == '请选择低密度脂蛋白'?'':'colorA4'"
					@click="handleTap('picker4')">
					{{label4}}
				</view>
			</view>
		</view>
		<u-line />


		<view class="weui-flex">
			<view>
				<view class="placeholder titleView">
					总胆固醇
				</view>
			</view>
			<view class="weui-flex__item">
				<view class="placeholder toolView" :class="label5 == '请选择总胆固醇'?'':'colorA4'"
					@click="handleTap('picker5')">
					{{label5}}
				</view>
			</view>
		</view>
		<u-line />

		<view class="weui-flex">
			<view>
				<view class="placeholder titleView">
					选择时间
				</view>
			</view>
			<view class="weui-flex__item">
				<view class="placeholder toolView" :class="value1==''?'':'colorA4'" @click="handleTap('picker1')">
					{{value1==''?label:value1.replace(/-/g,".")}}
				</view>
			</view>
		</view>
		<button class="relevance-btn" type="default" :disabled="disabled||value1==''?true:false"
			:class="value1==''?'disabledbg':''"
			@tap="addRecord(value2,value3,value4,value5,value1)">保存</button>
		<!-- 日期选择 -->
		<lb-picker ref="picker1" v-model="value1" :format="curFormat" display-format="YYYY-MM-DD-HH-mm-ss"
			mode="dateSelector" @change="handleChange" @confirm="handleConfirm" @cancel="handleCancel"
			start-date="2021-1-1" :end-date="endTime">
		</lb-picker>
		<!-- end -->
		<!-- 血压选择 -->
		<!-- 	<lb-picker ref="picker2" v-model="value2" mode="multiSelector" :list="list2" :level="2"
			:dataset="{ name: 'label2' }" @change="handleChange" @confirm="handleConfirm" @cancel="handleCancel">
		</lb-picker> -->
		<lb-picker ref="picker2" v-model="value2" mode="unlinkedSelector" :list="list2" @change="handleChange"
			@confirm="handleConfirm2" @cancel="handleCancel">
		</lb-picker>

		<lb-picker ref="picker3" v-model="value3" mode="unlinkedSelector" :list="list3" @change="handleChange"
			@confirm="handleConfirm3" @cancel="handleCancel">
		</lb-picker>


		<lb-picker ref="picker4" v-model="value4" mode="unlinkedSelector" :list="list4" @change="handleChange"
			@confirm="handleConfirm4" @cancel="handleCancel">
		</lb-picker>

		<lb-picker ref="picker5" v-model="value5" mode="unlinkedSelector" :list="list5" @change="handleChange"
			@confirm="handleConfirm5" @cancel="handleCancel">
		</lb-picker>
		<!-- end -->
	</view>
</template>

<script>
	import dayjs from '@/common/utils/day/day.js'
	import lbPicker  from '@/pages/subpackage/components/lb-picker/index';
	import uLine from "@/uview-ui/components/u-line/u-line.vue"
	export default {
		components: {
			lbPicker,
			uLine,
		},
		data() {
			return {
				itemType:[],
				listLength: {
				},
				curFormat: 'YYYY-MM-DD HH:mm:ss',
				disabled: false,
				endTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
				indicId: '', //指标id
				value2: [4,
					'',
					'',
					'',
					'mmol/L',
				],
				value4: [3,
					'',
					'',
					'',
					'mmol/L',
				],
				value5: [3,
					'',
					'',
					'',
					'mmol/L',
				],
				label2: '请选择高密度脂蛋白',
				value1: '',
				label: '请选择时间',
				list4: [

				],
				label4: '请选择低密度脂蛋白',

				list5: [

				],
				label5: '请选择总胆固醇',
				list2: [

				],
				label3: '请选择甘油三酯',
				value3: [
					3,
					'',
					'',
					'',
				],
				list3: [

				],
			}
		},
		onLoad(e) {
			this.indicId = e.indicId ? e.indicId : 7;
			// let list2 = this.list2,
			// 	arrheight = []; //身高
			// let list3 = this.list3,
			// 	arrwihgt = [],
			// 	minArr = [],
			// 	gArr = [],
			// 	diangArr10 = [];
			// for (let i = 0; i < 10; i++) {
			// 	gArr.push(i)
			// }
			// for (let i = 0; i < 10; i++) {
			// 	diangArr10.push('.' + i)
			// }
			// for (let i = 0; i < 100; i++) {
			// 	minArr.push('.' + i)
			// }
			// for (let i = 0; i < 50; i++) {
			// 	arrheight.push(i)
			// }
			// for (let i = 25; i < 301; i++) {
			// 	arrwihgt.push(i)
			// }
			// this.list2[0] = gArr; //高密度蛋白
			// this.list2[1] = diangArr10; //高密度蛋白
			// this.list2[2] = gArr; //高密度蛋白
			// this.list2[3] = gArr; //高密度蛋白小数

			// this.list4[0] = arrheight; //低密度蛋白
			// this.list4[1] = minArr; //低密度蛋白小数

			// this.list5[0] = arrheight; //胆固醇
			// this.list5[1] = minArr; //胆固醇小数


			// this.list3[0] = arrheight; //
			// this.list3[1] = minArr; //胆固醇小数
			// let gender = uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').gender;
			// if (gender == 2) { //女性
			// 	this.value3 = [
			// 		'',
			// 		'',
			// 		160,
			// 		'cm',
			// 		'',
			// 		''
			// 	]
			// }
			this.getRangeIndicator()
		},
		methods: {
			//测量指标范围列表
			getRangeIndicator() {
				this.$api.get(global.apiUrls.getRangeIndicator, {})
					.then(res => {
						let result = res.data.result,
							range;
						for (let i = 0; i < result.length; i++) {
							if ('FOUR_ITEMS_BLOOD_LIPID' == result[i].itemCode) { //	尿酸
								range = result[i].valueExpression
							}
						}
						let listArr = ['list3',
							'list2',
							'list4',
							'list5'
						]

						range.forEach((item, index) => {
							this.itemType.push(item.type)
							this.$basejs.funFor(item.range, this, listArr[index],'mmol/L',item.type)
						})
					})
			},
			handleConfirm5(e) {
				this.label5 = this.$basejs.itemFor(this, 'list5', e.item, true,this.itemType[3])
			},
			handleConfirm4(e) {
				this.label4 = this.$basejs.itemFor(this, 'list4', e.item, true,this.itemType[2])
			},
			//身高
			handleConfirm3(e) {
				this.label3 =this.$basejs.itemFor(this, 'list3', e.item, true,this.itemType[0])
			},
			getLastTimeG() {
				let _this = this;
				this.$loginl.get(global.apiUrls.getUserInfoWidth, {})
					.then(res => {
						if (res.data.code == 1000) { //一天数据
							// console.log(res.data.result.height,'152222222222')

							if (res.data.result.height) {
								let height = res.data.result.height * 1 //
								_this.value3 = [
									'',
									'',
									height,
									'cm',
									'',
									''
								]
								_this.label3 = res.data.result.height
							}
							if (res.data.result.weight) {
								let weight = res.data.result.weight.toString();
								if (weight.split('.')) { //有小数点
									weight = weight.split('.');
									_this.value2 = [
										'',
										'',
										parseInt(weight[0]),
										parseInt(weight[1]),
										'kg',
										'',
										''
									]
								} else { //没小数点
									_this.value2 = [
										'',
										'',
										parseInt(weight),
										0,
										'kg',
										'',
										''
									]
								}

								_this.label2 = res.data.result.weight
							}

						}
					})
			},
			// 体重
			handleConfirm2(e) {
				console.log(e)
				this.label2 = this.$basejs.itemFor(this, 'list2', e.item, true,this.itemType[1])
			},
			// 记录体重
			addRecord(value2, value3, value4, value5, time) {
				console.log(value2, value3, value4, value5, time, 2022)
				this.disabled = true;
				let healthData = {
					topLipoprotein: this.label2!='请选择高密度脂蛋白'? this.$basejs.itemFor(this, 'list2', value2, false,this.itemType[1]) :'', //
					triglyceride:this.label3 != '请选择甘油三酯'?  this.$basejs.itemFor(this, 'list3', value3, false,this.itemType[0]):'',
					lowLipoprotein:this.label4 != '请选择低密度脂蛋白'?  this.$basejs.itemFor(this, 'list4', value4, false,this.itemType[2]):'',
					cholesterol: this.label5!='请选择总胆固醇'?this.$basejs.itemFor(this, 'list5', value5, false,this.itemType[3]):''
				}
				console.log(healthData, '3055555555')
				let _this = this,
					fdata = {
						deviceType: 'FOUR_ITEMS_BLOOD_LIPID',
						recordTime: dayjs(time).format('YYYY-MM-DD'),
						createTime: time,
						inputType: 1, //1手动 2设备
						userId: uni.getStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').userId,
						mac: '', //设备mac
						deviceId: '', //设备id
						healthDataId: '',
						healthData: JSON.stringify(healthData),
					};
				this.$api.post(global.apiUrls.addRecord, fdata).then(res => {
					if (res.data.code == 1000) {
						_this.value2[0] = '请选择体重'
						_this.value1 = ''
						uni.showToast({
							title: res.data.message,
							duration: 2000
						});
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							});
						}, 2000);
					} else {
						uni.showToast({
							title: res.data.message,
							icon: "none",
							duration: 2000
						});
					}
					_this.disabled = false;
				}).catch(err => {
					_this.disabled = false;
				})
			},
			handleTap(name) {
				this.$refs[name].show()
			},
			handleChange(e) {
				console.log('change::', e)
			},
			handleConfirm(e) {
				console.log(e)
			},
			handleCancel(e) {
				console.log('cancel::', e)
			},
		}
	}
</script>

<style lang="scss">
	@import "./record.scss"
</style>
